import type { ResponseOption } from "../../res/ResponseOption.js";
import { hex } from "../../util.js";
import { fields, ResOp } from "./utils.js";

export const varChange: ResponseOption = {
    name: "0x02 图元变量改变通知",
    description: "由服务端通知客户端，图元绑定的变量发生改变的消息",
    fields: [
        fields.op(ResOp.VarChange),
        fields.crc,
        fields.length,
        {
            name: "画面 ID",
            kind: "u16",
        },
        {
            name: "变量列表",
            kind: "custom",
            desc: "每个变量由 图元 ID + 属性 + 索引 + 值 组成",
            matcher(data) {
                let str = "";
                while (data.length > 0) {
                    const vl = data.u8(0);
                    data.consume(1);
                    str += hex(vl) + " ";
                }
                return str;
            },
        },
    ],
};
